package com.xr.common.sender;

import com.alibaba.fastjson.JSONObject;
import com.xr.common.entity.ExceptionLog;
import com.xr.common.entity.OperationLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class LogSender {

	@Resource
	private RabbitTemplate rabbitTemplate;

	public void sendOperationLog(OperationLog operationLog) {
		String operationLogJsonStr = JSONObject.toJSONString(operationLog);
		log.info("当前时间戳<{}>，LogSender发送消息<{}>到operationLogQueue队列", System.currentTimeMillis(), operationLogJsonStr);
		rabbitTemplate.convertAndSend("operationLogTopicExchange", "operationLogRoutingKey", operationLogJsonStr);
	}

	public void sendExceptionLog(ExceptionLog exceptionLog) {
		String exceptionLogJsonStr = JSONObject.toJSONString(exceptionLog);
		log.info("当前时间戳<{}>，LogSender发送消息<{}>到exceptionLogQueue队列", System.currentTimeMillis(), exceptionLogJsonStr);
		rabbitTemplate.convertAndSend("exceptionLogTopicExchange", "exceptionLogRoutingKey", exceptionLogJsonStr);
	}

}
